%%%-------------------------------------------------------------------
%%% @author kk
%%% @copyright (C) 2024, <COMPANY>
%%% @doc
%%% 获得数字列表或元组中的最大最小值
%%% @end
%%% Created : 18. 7月 2024 11:26
%%%-------------------------------------------------------------------
-module(d1).
-author("kk").

%% API
-export([start/0,start2/0]).

%% 查找最大值
my_max([]) -> error;
my_max([X]) -> X;  %% [X] = [X | []]
my_max([X | T]) ->
  M = my_max(T),
  if
    X > M -> X;
    true -> M
  end.

%% 查找最小值
my_min([]) -> error;
my_min([X]) -> X;
my_min([X | T]) ->
  M = my_min(T),
  if
    X < M -> X;
    true -> M
  end.

start() ->
%%  X = my_max([5, 3, 9, 1, 6]),
%%  X = my_max([]),
  X = my_max([5]),
  io:fwrite("~w", [X]).

start2() ->
  X = my_min([5, 3, 9, 1, 0, 6]),
  io:fwrite("~w", [X]).



  
